home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / STRCSPAN.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  1KB  |  81 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7. ;
  8. ;
  9. ; strcspan-    Returns the number of characters at the beginning of a string
  10. ;        which are NOT from a specified set.
  11. ;
  12. ; inputs:
  13. ;
  14. ;    ES:DI-  Points at string to test.
  15. ;    DX:SI-    Points at set of characters (zero terminated string).
  16. ;
  17. ; outputs:
  18. ;
  19. ;    CX-    Number of characters not in the set which are the prefix of
  20. ;        the test string.
  21. ;
  22. ;
  23. ;
  24. ;
  25.         public    sl_strcspan
  26. ;
  27. sl_strcspan    proc    far
  28.         pushf
  29.         push    es
  30.         push    ds
  31.         push    ax
  32.         push    bx
  33.         push    dx
  34.         push    si
  35.         push    di
  36.         cld
  37. ;
  38.         mov    ax, es
  39.         mov    es, dx
  40.         mov    ds, ax
  41.         xchg    si, di
  42. ;
  43.         mov    bx, di            ;Preserve ptr to char set.
  44.         mov    cx, 0ffffh
  45.         mov    al, 0
  46.     repne    scasb                ;Compute length of char set.
  47.         neg    cx
  48.         dec    cx
  49.         dec    cx
  50.         mov    dx, cx            ;Save for use later.
  51. ;
  52. ; Okay, now we can see how many characters from the set match the prefix
  53. ; characters in the string.
  54. ;
  55. StrLp:        lodsb                ;Get next char in string.
  56.         mov    cx, dx            ;Get length of char set.
  57.         mov    di, bx            ;Get ptr to char set
  58.     repne    scasb                ;See if in set
  59.         jnz    StrLp            ;Repeat while not in set.
  60. ;
  61.         pop    di
  62.         mov    cx, di
  63.         sub    cx, si
  64.         neg    cx
  65.         dec    cx    
  66.         pop    si
  67.         pop    dx
  68.         pop    bx
  69.         pop    ax
  70.         pop    ds
  71.         pop    es
  72.         popf
  73.         ret
  74. sl_strcspan    endp
  75. ;
  76. ;
  77. ;
  78. ;
  79. stdlib        ends
  80.         end
  81.